<template>
  <el-container class="home-container">
    <!-- 头部 -->
    <el-header>
      <div>
        <img src="../assets/logo.png" class="png" />
        <span>研究生招生信息管理系统</span>
      </div>
      <el-button type="danger" @click="logout">退出登录</el-button>
    </el-header>
    <!-- 页面主体 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="200px">
        <!-- 侧边栏菜单 -->
        <el-menu
          background-color="#28282b"
          text-color="#fff"
          active-text-color="#ffd04b"
          unique-opened
          :router="true"
          :default-active="activepath"
        >
          >
          <!-- 一级菜单 -->
          <el-menu-item
            v-for="item in items"
            :index="item.route"
            @click="saveNavState(item.route)"
          >
            <!-- 一级菜单模板 -->
            <template slot="title">
              <!-- 图标 -->
              <i class="el-icon-s-custom"></i>
              <!-- 文本 -->
              <span>{{ item.name }}</span>
            </template>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <!-- 右侧 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      items: [
        { route: '/examinee', name: '考生基本信息' },
        { route: '/major', name: '专业字典' },
        { route: '/firstgrade', name: '初试成绩录入' },
        { route: '/line', name: '设置分数线' },
        { route: '/secondgrade', name: '复试成绩录入' },
        { route: '/admission', name: '查看录取情况' },
        { route: '/info', name: '数据统计' },
      ],
      activepath: '',
    }
  },
  created() {
    this.activepath = window.sessionStorage.getItem('activepath')
  },
  methods: {
    logout() {
      this.$router.push('/login')
    },
    saveNavState(activepath){
      window.sessionStorage.setItem('activepath', activepath)
      this.activepath = activepath
    }
  },
}
</script>

<style lang="less" scoped>
.png {
  width: 10%;
  height: 10%;
  padding-left: 0;
  align-items: center;
}
.home-container {
  height: 100%;
}
.el-header {
  background-color: #1b1c1d;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}
.el-aside {
  background-color: #28282b;
}
.el-main {
  background-color: #e9e9e9;
}
</style>
